import styled, {css} from "styled-components";
import {useEffect, useState} from "react";

const HeaderStyle = styled.div`
  position: absolute;
  top: 0;
  /* background-color: #000; */
  color: #fff;
  width: 100%;
  height: 100px;
  line-height: 100px;
  font-size: 36px;
  font-weight: bold;
  padding-left: 10px;
  transition: width 0.5s ease-in-out;
`;
const AnimatedParagraph = styled.p<{
  $isActive: boolean;
}>`
  height: 100%;
  font-size: 0;
  opacity: 0;
  margin: 0px;
  transition: opacity 0.5s ease-in-out; /* 文本的过渡动画 */
  ${(props) =>
    props.$isActive &&
    css`
      opacity: 1;
      font-size: 16px;
    `}
`;

function Header() {
  const [isActive, setIsActive] = useState(false);
  useEffect(() => {
    const delay = setTimeout(() => {
      setIsActive(true);
    }, 500);
    return () => clearTimeout(delay);
  }, []);
  return (
    <>
      <HeaderStyle>
        <AnimatedParagraph $isActive={isActive}>
          Welcome to the My Home!
        </AnimatedParagraph>
      </HeaderStyle>
    </>
  );
}

export default Header
